# Build recipe for utmpset.
#
# Copyright (c) 2017 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

program=runit
version=2.1.2
pkgname=utmpset
pkgversion=2.1.2
release=1

tarname=${program}-${version}.tar.gz

# Remote source(s)
fetch=http://smarden.org/runit/$tarname

description="
Logout a line from utmp and wtmp file.

The utmpset program modifies the user accounting database utmp(5) and
optionally wtmp(5) to indicate that the user on the terminal line has
logged out.
"

homepage=http://smarden.org/runit/utmpset.8.html
license=BSD

# Source documentation
docs="COPYING README"
docsdir="${docdir}/${pkgname}-${pkgversion}"

# Where the source resides
srcdir=admin/${program}-${version}

build()
{
    set -e

    unpack "${tardir}/$tarname"

    cd "$srcdir"

    cd src

    # Pick up Qi's CFLAGS, LDFLAGS
    sed -i "s|gcc -O2|gcc $QICFLAGS|" ./conf-cc
    sed -i "s|gcc -s|gcc $QILDFLAGS -static|" ./conf-ld

    make utmpset

    # Install the program and the documentation

    mkdir -p "${destdir}/usr/sbin" "${destdir}/${mandir}/man8"

    cp -p utmpset "${destdir}/usr/sbin/"
    chmod 755 "${destdir}/usr/sbin/utmpset"

    cd ..

    cp -p man/utmpset.8 "${destdir}/${mandir}/man8/"
    chmod 644 "${destdir}/${mandir}/man8/utmpset.8"

    # Compress man page
    lzip -9 "${destdir}/${mandir}/man8/utmpset.8"

    # Copy documentation
    mkdir -p "${destdir}${docsdir}"

    for file in $docs
    do
        ( cd package && cp -p $file "${destdir}${docsdir}" )
    done
}

